/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : date_reserve.js                                 
*  Description  : 실시간 예약 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-05-04  김효순    Created.  
*  2012-05-07  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	// 달력
	function clsCalendar()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsCalendar.prototype = {
		_init: function(){
			var $layer = $("div#container section#left_content article.calendar");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			
			this.infoData = {
				"달력일": null
				, "시작일": null
			}
		}
		, setInfo: function(key, val){
			switch(key){
				case "달력일":
					val.setDate(1);
					break;
				case "시작일":
					if(this.infoData["달력일"] && val.getMonth() != this.infoData["달력일"].getMonth()){
						var nDate = new Date();
						nDate.setTime(val.getTime());
						nDate.setDate(1);
						
						this.infoData["달력일"] = nDate;
					}
					break;
			}
			
			this.infoData[key] = val;
			this.display();
		}
		, nextMonth: function(){
			this.infoData["달력일"].setMonth(this.infoData["달력일"].getMonth()+1);
			this.display();
		}
		, prevMonth: function(){
			this.infoData["달력일"].setMonth(this.infoData["달력일"].getMonth()-1);
			this.display();
		}
		, getSDate: function(){
			return this.infoData["시작일"];
		}
		, display: function(){
			if(!(this.infoData["달력일"] &&  this.infoData["시작일"])) return;
			
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			var dayOfWeek = this.infoData["달력일"].getDay();
			var endDay = new Date(this.infoData["달력일"].getFullYear(), this.infoData["달력일"].getMonth()+1, 0).getDate();
			
			$layer.find("dt:first").contents().eq(0).remove().end().end().prepend((this.infoData["달력일"].getMonth()+1) + "월");
			
			$layer.find("tbody").empty();
			for(var i=1;i-dayOfWeek<=endDay;i+=7){
				$layer.find("tbody").append($element.clone(true));
			}
			
			$layer.find("tbody tr td").each(function(n){
				var thisDay = n-dayOfWeek+1;
				var today = new Date();
				today.setHours(0);
				today.setMinutes(0);
				today.setSeconds(0);
				today.setMilliseconds(0);
				
				$(this).attr("class", "").html("");
				if(thisDay > 0 && thisDay <= endDay){
					var newDate = new Date();
					newDate.setTime(thisClass.infoData["달력일"].getTime());
					newDate.setDate(thisDay);
					
					var endDate = new Date();
					endDate.setTime(thisClass.infoData["시작일"].getTime());
					endDate.setDate(endDate.getDate() + 13);
					
					$(this).html(thisDay).data("날짜", newDate);
					if(newDate.getTime() == today.getTime()) $(this).addClass("today");
					if(newDate.getTime() == thisClass.infoData["시작일"].getTime()) $(this).addClass("start_day");
					if(newDate.getTime() > thisClass.infoData["시작일"].getTime() && newDate.getTime() <= endDate.getTime()) $(this).addClass("res_day");
				}else{
					$(this).data("날짜", null);
				}
			});
		}
		, $getBtnPrev: function(){
			return this._HTMLDom["$layer"].find("span.bt_prev");
		}
		, $getBtnNext: function(){
			return this._HTMLDom["$layer"].find("span.bt_next");
		}
		, $getBtnCalendar: function(){
			return this._HTMLDom["$layer"].find("tbody tr td");
		}
	}
	
	// 지역선택(좌메뉴)
	function clsCourseList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsCourseList.prototype = {
		_init: function(){
			var $layer = $("div#container section#left_content article.area_choice dl");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("label:first").clone(true)
			}
			
			//this.setAreaList([]);
			//this.setCourseList([]);
		}
		, setAreaList: function(thisData){
			this.listData = [{
				"키": ""
				, "지역명": "전체"
			}].concat(thisData);
		}
		, setCourseList: function(thisData){
			for(var i=0;i<thisData.length;i++){
				for(var j=0;j<this.listData.length;j++){
					if(this.listData[j]["키"] == thisData[i]["지역키"]) break;
				}
				if(j < this.listData.length){
					if(!this.listData[j]["코스리스트"]) this.listData[j]["코스리스트"] = new Array();
					this.listData[j]["코스리스트"].push(thisData[i]);
				}
			}
			
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append("<dt />").find("dt:last").append($element.clone(true));
				
				if(this.listData[i]["코스리스트"]){
					$layer.append("<dd />");
					for(var j=0;j<this.listData[i]["코스리스트"].length;j++){
						$layer.find("dd:last").append($element.clone(true));
					}
					$layer.find("dd:last label").each(function(n){
						$(this).find(":checkbox").val(thisClass.listData[i]["코스리스트"][n]["키"]);
						$(this).contents().eq(1).remove().end().end().append(thisClass.listData[i]["코스리스트"][n]["코스명"]);
					});
				}
			}
			$layer.find("dt label").each(function(n){
				$(this).contents().eq(1).remove().end().end().append(thisClass.listData[n]["지역명"]);
			});
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var szRet = "";
			
			$layer.find(":checkbox:checked").filter(function(){
				if($(this).parent().parent().get(0).tagName.toUpperCase() == "DD") return true;
				else return false;
			}).each(function(){
				if(szRet) szRet += ",";
				szRet += $(this).val();
			});
			
			return szRet;
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.parent().find("div#tmpSpin").length == 0){
				$layer.parent().prepend("<div id='tmpSpin' style='position:absolute; width:160px; height:150px;' />");
			}
			$layer.parent().find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parent().find("div#tmpSpin").hide().spin(false);
			$layer.show();
		}
		, $getCheckBoxs: function(){
			return this._HTMLDom["$layer"].find("input:checkbox");
		}
		, onCheck: function($obj){
			var $layer = this._HTMLDom["$layer"];
			
			var n = this.$getCheckBoxs().index($obj);
			var bCheck = $obj.is(":checked");
			
			if(n == 0){
				this.$getCheckBoxs().filter(":gt(0)").attr("checked", bCheck);
				return;
			}
			
			var $parent = $obj.parent().parent();
			
			switch($parent.get(0).tagName.toUpperCase()){
				case "DT":
					$parent.next("dd").find(":checkbox").attr("checked", bCheck);
					break;
				case "DD":
					$parent.prev("dt").find(":checkbox").attr("checked", ($parent.find(":checkbox").length == $parent.find("input:checked").length));
					break;
			}
			
			this.$getCheckBoxs().eq(0).attr("checked", (this.$getCheckBoxs().filter(":gt(0)").length <= this.$getCheckBoxs().filter(":checked").length));
		}
	}
	
	// 2주력
	function clsWeekCalendar()
	{
		this._HTMLDom = null;
		this.sDate = null;
		this.selDate = null;
		
		this._init();
	}
	
	clsWeekCalendar.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_area:first thead");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			var thisClass = this;
			this.$getDateBox().css("cursor", "pointer");
		}
		, setDate: function(newDate){
			this.sDate = newDate;
			this.display();
		}
		, setSelDate: function(newDate){
			this.selDate = newDate;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			var aWeekday = ["일", "월", "화", "수", "목", "금", "토"];
			
			$layer.find("th:gt(1)").filter("th:not(.th_next)").css("cursor", "pointer").each(function(n){
				var newDate = new Date();
				newDate.setTime(thisClass.sDate.getTime());
				newDate.setDate(newDate.getDate() + n);
				
				$(this).data("date", newDate);
				$(this).find("p:eq(0)").html(aWeekday[newDate.getDay()]);
				$(this).find("p:eq(1)").html(newDate.getDate());
				
				$(this).attr("class", "");
				
				switch(newDate.getDay()){
					case 0:
						$(this).addClass("holiday");
						break;
					case 6:
						$(this).addClass("satday");
						break;
				}
				
				if(thisClass.selDate && newDate.getTime() == thisClass.selDate.getTime()) $(this).addClass("day_over");
			});
			
			// 두번째 2주력 생성을 위해
			$(this).trigger("evtFinishDisplay", [$layer.find("tr").clone(true)]);
		}
		, getDate: function(){
			return this.sDate;
		}
		, getSelDate: function(){
			return this.selDate;
		}
		, $getBtnPrev: function(){
			return this._HTMLDom["$layer"].find("th.th_prev");
		}
		, $getBtnNext: function(){
			return this._HTMLDom["$layer"].find("th.th_next");
		}
		, $getDateBox: function(){
			return this._HTMLDom["$layer"].find("th:gt(1)").filter("th:not(.th_next)")
		}
		, getSatIndexs: function(){
			var $layer = this._HTMLDom["$layer"];
			var $sat = $layer.find("th").filter(function(){
				return $(this).hasClass("satday");
			});
			
			return [$layer.find("th:gt(1)").index($sat.eq(0)), $layer.find("th:gt(1)").index($sat.eq(1))];
		}
		, getSunIndexs: function(){
			var $layer = this._HTMLDom["$layer"];
			var $sun = $layer.find("th").filter(function(){
				return $(this).hasClass("holiday");
			});
			
			return [$layer.find("th:gt(1)").index($sun.eq(0)), $layer.find("th:gt(1)").index($sun.eq(1))];
		}
		, disable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_area").hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_area").show();
		}
	}
	
	// 지역선택
	function clsAreaList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this.idx = null;
		
		this._init();
	}
	
	clsAreaList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.area_search div.selectlayer02:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("li:first").clone(true)
			}
			
			this.disable();
			
			this.idx = 0;
			this.setList([]);
		}
		, setList: function(thisData){
			this.listData = [{
				"키": ""
				, "지역명": "지역 선택"
			}].concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("ul").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("ul").append($element.clone(true));
			}
			$layer.find("li a").each(function(n){
				$(this).html(thisClass.listData[n]["지역명"]);
			});
		}
		, setKey: function(idx){
			this.idx = idx;
			this.displayTitle();
		}
		, displayTitle: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("a:first").html(this.listData[this.idx]["지역명"]);
			this.hide();
		}
		, $getDisplay: function(){
			return this._HTMLDom["$layer"].find("a:first");
		}
		, show: function(){
			this._HTMLDom["$layer"].find("ul").show(300);
		}
		, hide: function(){
			this._HTMLDom["$layer"].find("ul").hide(300);
		}
		, getValue: function(){
			return this.listData[this.idx]["키"];
		}
		, disable: function(){
			this._HTMLDom["$layer"].hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].show();
		}
		, $getBtns: function(){
			return this._HTMLDom["$layer"].find("li a");
		}
	}
	
	// 골프장 선택
	function clsGolfList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this.idx = null;
		
		this._init();
	}
	
	clsGolfList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.area_search div.selectlayer02:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("li:first").clone(true)
			}
			
			this.disable();
			
			this.reset();
		}
		, reset: function(){
			this.idx = 0;
			this.setList([]);
			
			this.hide();
		}
		, setList: function(thisData){
			this.listData = [{
				"키": ""
				, "골프장명": "골프장 선택"
			}].concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("ul").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("ul").append($element.clone(true));
			}
			$layer.find("li a").each(function(n){
				$(this).html(thisClass.listData[n]["골프장명"]);
			});
		}
		, setKey: function(idx){
			this.idx = idx;
			this.displayTitle();
		}
		, displayTitle: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("a:first").html(this.listData[this.idx]["골프장명"]);
			this.hide();
		}
		, $getDisplay: function(){
			return this._HTMLDom["$layer"].find("a:first");
		}
		, show: function(){
			this._HTMLDom["$layer"].find("ul").show(300);
		}
		, hide: function(){
			this._HTMLDom["$layer"].find("ul").hide(300);
		}
		, getValue: function(){
			return this.listData[this.idx]["키"];
		}
		, disable: function(){
			this._HTMLDom["$layer"].hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].show();
		}
		, $getBtns: function(){
			return this._HTMLDom["$layer"].find("li a");
		}
	}
	
	// 2주력 리스트용
	function clsWeekCalendar2()
	{
		this._HTMLDom = null;
		this.sDate = null
		
		this._init();
	}
	
	clsWeekCalendar2.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.day_ch thead");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.disable();
			
			$layer.find("th:gt(0)").remove();
		}
		, display: function($obj){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("th:gt(0)").remove();
			$layer.find("tr").append($obj.find("th:gt(0)"));
		}
		, $getDateBox: function(){
			return this._HTMLDom["$layer"].find("th:gt(1)").filter("th:not(.th_next)")
		}
		, disable: function(){
			this._HTMLDom["$layer"].parents("article.day_ch").hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].parents("article.day_ch").show();
		}
	}
	
	// 날짜별 코스리스트
	function clsCourseTimeList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this.satIndexs = null;
		this.sunIndexs = null;
		
		this._init();
	}
	
	clsCourseTimeList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_area:first tbody");
			this._HTMLDom = {
				"$layer": $layer
				, "$areaElement": $layer.find("tr:first").clone(true)
				, "$element": $layer.find("tr:eq(1)").clone(true)
			}
			
			$layer.empty();
		}
		, setList: function(areaData){
			this.listData = areaData;
		}
		, setCourseList: function(courseData){
			for(var i=0;i<this.listData.length;i++){
				this.listData[i]["코스리스트"] = new Array();
			}
			
			for(var i=0;i<courseData.length;i++){
				for(var j=0;j<this.listData.length;j++){
					if(this.listData[j]["키"] == courseData[i]["지역키"]) break;
				}
				if(j < this.listData.length){
					this.listData[j]["코스리스트"].push(courseData[i]);
				}
			}
			
			this.display();
		}
		, setSatIndexs: function(idxs){
			this.satIndexs = idxs;
		}
		, setSunIndexs: function(idxs){
			this.sunIndexs = idxs;
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $areaElement = this._HTMLDom["$areaElement"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($areaElement.clone(true));
				if(this.listData[i]["코스리스트"].length > 0){
					for(j=0;j<this.listData[i]["코스리스트"].length;j++){
						$layer.append($element.clone(true));
						$layer.find("tr:last td:not(:last)").each(function(n){
							if(n == 0){
								$(this).html(thisClass.listData[i]["코스리스트"][j]["코스명"]);
							}else{
								$(this).attr("class", "");
								
								$(this).find("p.am").html(thisClass.listData[i]["코스리스트"][j]["리스트"][n-1]["시간1"]);
								$(this).find("p.pm").html(thisClass.listData[i]["코스리스트"][j]["리스트"][n-1]["시간2"]);
							}
						});
					}
				}
			}
			
			$layer.find("tr td.area_c").each(function(n){
				$(this).html("[" + thisClass.listData[n]["지역명"] + "]");
			});
			
			$layer.find("tr").has("td:not(.area_c)").find("td:nth-child(" + (this.satIndexs[0]+2) + ")").addClass("satday");
			$layer.find("tr").has("td:not(.area_c)").find("td:nth-child(" + (this.satIndexs[1]+2) + ")").addClass("satday");
			
			$layer.find("tr").has("td:not(.area_c)").find("td:nth-child(" + (this.sunIndexs[0]+2) + ")").addClass("holiday");
			$layer.find("tr").has("td:not(.area_c)").find("td:nth-child(" + (this.sunIndexs[1]+2) + ")").addClass("holiday");
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.hide();
			if($layer.parent().parent().find("div#tmpSpin").length == 0){
				$layer.parent().parent().append("<div id='tmpSpin' style='position:relative; width:700px; height:100px;' />");
			}
			$layer.parent().parent().find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parent().parent().find("div#tmpSpin").hide().spin(false);
			$layer.show();
		}
		, disable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_area").hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_area").show();
		}
	}
	
	// 예약리스트
	function clsReserveList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this.orderIdx = null;
		this.idx = null;
		
		this._init();
	}
	
	clsReserveList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_list tbody");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			
			this.orderIdx = 1;
			
			this.setList([]);
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.idx = null;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($element.clone(true));
			}
			$layer.find("tr").each(function(n){
				$(this).attr("class", "");
				
				$(this).find("td:eq(0)").html(thisClass.listData[n]["코스명"]);
				$(this).find("td:eq(1)").html(thisClass.listData[n]["시간"]);
				$(this).find("td:eq(2)").html(thisClass.listData[n]["홀명"]);
				$(this).find("td:eq(3) p:eq(0)").html(thisClass.listData[n]["가격"]);
				$(this).find("td:eq(3) p:eq(1)").html(thisClass.listData[n]["원가"]);
				
				$(this).find("td:eq(4)").find("li").each(function(i){
					if(thisClass.listData[n]["이벤트"].indexOf($(this).find("img").attr("alt")) == -1) $(this).html("");
				});
			}).hover(function(){
				$(this).addClass("tr_on");
			}
			, function(){
				$(this).removeClass("tr_on");
			});
			
			this.displayOrder();
		}
		, displayOrder: function(){
			this.$getBtnOrder().find("span").attr("class", "");
			this.$getBtnOrder().eq(this.orderIdx).find("span").addClass("th_t");
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			if($layer.parents("article.reserve_list").find("div#tmpSpin").length == 0){
				$layer.parents("article.reserve_list").append("<div id='tmpSpin' style='position:absolute; width:700px; height:100px;' />");
			}
			$layer.parents("article.reserve_list").find("div#tmpSpin").show().spin();
			
			$layer.hide();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.parents("article.reserve_list").find("div#tmpSpin").hide().spin(false);
			$layer.show();
		}
		, disable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_list").hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].parents("article.reserve_list").show();
		}
		, $getBtnOrder: function(){
			return this._HTMLDom["$layer"].prev("thead").find("th");
		}
		, setOrder: function(idx){
			this.orderIdx = idx;
			this.displayOrder();
		}
		, getOrder: function(){
			return this.orderIdx;
		}
		, getCourseKey: function(){
			if(this.idx == null) return null;
			else return this.listData[this.idx]["코스키"];
		}
		, getKey: function(){
			if(this.idx == null) return null;
			else return this.listData[this.idx]["키"];
		}
		, setKey: function(key){
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i]["키"] == key) break;
			}
			if(i<this.listData.length) this.idx = i;
		}
		, $getBtnInfos: function(){
			return this._HTMLDom["$layer"].find("tr td:nth-child(6) a:first-child");
		}
		, $getBtnApplys: function(){
			return this._HTMLDom["$layer"].find("tr td:nth-child(6) a:nth-child(2)");
		}
		, setIdx: function(idx){
			this.idx = idx;
		}
	}
	
	// 예약정보
	function clsReserveInfo()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsReserveInfo.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_view_bg");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			
			$layer.find("p.golf_d span:eq(0)").html(this.infoData["코스명"]);
			$layer.find("p.golf_d span:eq(1)").html(this.infoData["홀명"]);
			$layer.find("p.res_date").contents().eq(0).before(this.infoData["날짜"] + ". " + this.infoData["요일"]).remove();
			$layer.find("p.res_date span").html(this.infoData["시간"]);
			$layer.find("div.res_price div.cost span").html(this.infoData["원가"]);
			$layer.find("div.res_price div.sale p.s_price span").html(this.infoData["가격"]);
			
			$layer.find("ul.ico_list li").each(function(n){
				if(thisClass.infoData["이벤트"].indexOf($(this).find("img").attr("alt")) == -1) $(this).find("img").hide();
				else $(this).find("img").show();
			});
		}
		, disable: function(){
			this._HTMLDom["$layer"].hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].show();
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div.reserve_view").children().hide();
			if($layer.find("div.reserve_view div#tmpSpin").length == 0){
				$layer.find("div.reserve_view").append("<div id='tmpSpin' style='position:relative; width:700px; height:150px;' />");
			}
			$layer.find("div.reserve_view div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div.reserve_view div#tmpSpin").hide().spin(false);
			$layer.find("div.reserve_view").children(":not(div#tmpSpin)").show();
		}
	}
	
	// 코스정보
	function clsCourseInfo()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsCourseInfo.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_detail");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("ul.co_info_tab").next("img").remove().end().after("<div id='idPic' style='height: 168px; width: 400px; padding:0; margin:0; overflow: hidden' />");
			
			fnLoadingJS("../js/jquery.cycle.js", function(){
				
			});
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div.detail_info:eq(0)").html(this.infoData["코스알림"]);
			$layer.find("div.detail_info:eq(1)").contents().eq(1).before(this.infoData["코스정보명"]).remove();
			if(this.infoData["자세히url"]){
				$layer.find("img[alt='코스자세히보기']").parent("a").attr({
					"target": "_blank"
					, "href": this.infoData["자세히url"]
				}).parent("span.bt_detail").show();
			}
			else{
				$layer.find("img[alt='코스자세히보기']").parents("span.bt_detail").hide();
			}
			$layer.find("ul.co_info_tab").empty();
			for(var i=0;i<this.infoData["이미지리스트"].length;i++){
				//$layer.find("ul.co_info_tab").append("<li><img src='" + this.infoData["이미지리스트"][i] + "' alt=''  width='35'  height='65'/></li>")
				$layer.find("div#idPic").append("<img src='" + this.infoData["이미지리스트"][i] + "' />");
			}
			$layer.find("div#idPic")
			.cycle({ 
			    fx:     'shuffle', 
			    speed:  'fast', 
			    timeout: 0, 
			    pager:  'ul.co_info_tab',
			    pagerAnchorBuilder: function(idx, slide) { 
			        return '<li><a href="#"><img src="' + slide.src + '" width="35" height="65" /></a></li>'; 
			    } 
			});
			$layer.find("div.detail_golf:eq(0)").contents().filter(function(){
				if(this.nodeType == 3 && this.data.trim()){return true;}
				else return false;
			}).before(this.infoData["골프장정보"]).remove();
			$layer.find("div.detail_info:eq(2) tbody tr:eq(0) td:eq(2)").html(this.infoData["주중회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(0) td:eq(3)").html(this.infoData["주말회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(1) td:eq(1)").html(this.infoData["주중비회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(1) td:eq(2)").html(this.infoData["주말비회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(2) td:eq(1)").html(this.infoData["주중주중회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(2) td:eq(2)").html(this.infoData["주말주중회원"]);
			$layer.find("div.detail_info:eq(2) tbody tr:eq(3) td:eq(1)").html(this.infoData["기타가격"]);
			$layer.find("div.item_info li:eq(0) div.item_cont").html(this.infoData["카트비"]);
			$layer.find("div.item_info li:eq(1) div.item_cont").html(this.infoData["캐디비"]);
			$layer.find("div.item_info li:eq(2) div.item_cont").html(this.infoData["대여채비"]);
			$layer.find("div.item_info li:eq(3) div.item_cont").html(this.infoData["대여화"]);
			$layer.find("div.item_info li:eq(4) div.item_cont").html(this.infoData["코스인원제한"]);
			$layer.find("div.detail_info:eq(3)").html(this.infoData["패널티정보"]);
		}
		, disable: function(){
			this._HTMLDom["$layer"].hide();
		}
		, enable: function(){
			this._HTMLDom["$layer"].show();
		}
		, spinStart: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.children().hide();
			if($layer.find("div#tmpSpin").length == 0){
				$layer.append("<div id='tmpSpin' style='position:relative; width:700px; height:150px;' />");
			}
			$layer.find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div#tmpSpin").hide().spin(false);
			$layer.children(":not(div#tmpSpin)").show();
		}
	}
	
	function clsComm()
	{
		// 지역리스트
		this.areaList = null;
		// 코스리스트
		this.courseList = null;
		
		this.courseTimeList = null;
		this.courseTimeRequest = null;
		
		// 골프장 리스트
		this.golfList = null;
		this.golfRequest = null;
		
		// 예약리스트
		this.reserveRequest = null;
		this.reserveList = null;
		
		// 예약정보
		this.reserveInfo = null;
		this.reserveInfoRequest = null;
		
		// 코스정보
		this.courseInfo = null;
		this.courseRequest = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.areaList = [
				{
					"키": null
					, "지역명": null
				}
			];
			
			this.courseList = [
				{
					"키": null
					, "지역키": null
					, "코스명": null
				}
			];
			
			this.courseTimeRequest = {
				"코스키": null
				, "시작일": null
			}
			
			this.courseTimeList = [
				{
					"코스키": null
					, "코스명": null
					, "지역키": null
					, "리스트": [
						{
							"날짜": null
							, "종류": null
							, "시간1": null
							, "시간2": null
						}
					]
				}
			];
			
			this.golfRequest = {
				"골프장키": null
			}
			
			this.golfList = [
				{
					"키": null
					, "골프장명": null
				}
			];
			
			this.reserveRequest = {
				"지역키": null
				, "골프장키": null
				, "날짜": null
				, "갯수": null
				, "정렬": null
			}
			
			this.reserveList = [
				{
					"키": null
					, "코스키": null
					, "코스명": null
					, "시간": null
					, "홀명": null
					, "가격": null
					, "원가": null
					, "이벤트": null
				}
			];
			
			this.reserveInfoRequest = {
				"예약키": null
			}
			
			this.reserveInfo = {
				"코스키": null
				, "코스명": null
				, "홀명": null
				, "날짜": null
				, "요일": null
				, "시간": null
				, "원가": null
				, "가격": null
				, "이벤트": null
			}
			
			this.courseRequest = {
				"코스키": null
			}
			
			this.courseInfo = {
				"코스키": null
				, "코스알림": null
				, "코스정보명": null
				, "자세히url": null
				, "이미지리스트": [
					
				]
				, "골프장정보": null
				, "주중회원": null
				, "주중비회원": null
				, "주중주중회원": null
				, "주말회원": null
				, "주말비회원": null
				, "주말주중회원": null
				, "기타가격": null
				, "카트비": null
				, "캐디비": null
				, "대여채비": null
				, "대여화": null
				, "코스인원제한": null
				, "패널티정보": null
			}
		}
		, getAreaList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.areaList = [
					{
						"키": "001"
						, "지역명": "서울"
					}
					, {
						"키": "002"
						, "지역명": "경기/인천"
					}
				];
				
				document.objControl.finishAreaList();
			}, 1000);
		}
		, getAreaData: function(){
			return this.areaList;
		}
		, getCourseList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.courseList = [
					{
						"키": "001"
						, "지역키": "001"
						, "코스명": "코스1"
					}
					, {
						"키": "002"
						, "지역키": "001"
						, "코스명": "코스2"
					}
					, {
						"키": "003"
						, "지역키": "002"
						, "코스명": "코스3"
					}
					, {
						"키": "004"
						, "지역키": "002"
						, "코스명": "코스4"
					}
				];
				
				document.objControl.finishCourseList();
			}, 1000);
		}
		, getCourseData: function(){
			return this.courseList;
		}
		, setCourseTimeRequest: function(key, val){
			this.courseTimeRequest[key] = val;
		}
		, getCourseTimeList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.courseTimeList = [
					{
						"코스키": "001"
						, "코스명": "하늘코스1"
						, "지역키": "001"
						, "리스트": [
							{
								"날짜": "2012-05-07"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-08"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-09"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-10"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-11"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-12"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-13"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-14"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-15"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-16"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-17"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-18"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-19"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
							, {
								"날짜": "2012-05-20"
								, "종류": "001"
								, "시간1": "01"
								, "시간2": "01"
							}
						]
					}
					, {
						"코스키": "002"
						, "코스명": "하늘코스2"
						, "지역키": "002"
						, "리스트": [
							{
								"날짜": "2012-05-07"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-08"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-09"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-10"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-11"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-12"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-13"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-14"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-15"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-16"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-17"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-18"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-19"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
							, {
								"날짜": "2012-05-20"
								, "종류": "001"
								, "시간1": "02"
								, "시간2": "02"
							}
						]
					}
				];
				
				document.objControl.finishCourseTimeList();
			}, 1500);
		}
		, getCourseTimeData: function(){
			return this.courseTimeList;
		}
		, setGolfRequest: function(key, val){
			this.golfRequest[key] = val;
		}
		, getGolfList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.golfList = [
					{
						"키": "001"
						, "골프장명": "골프장1"
					}
					, {
						"키": "002"
						, "골프장명": "골프장2"
					}
					, {
						"키": "003"
						, "골프장명": "골프장3"
					}
					, {
						"키": "004"
						, "골프장명": "골프장4"
					}
				];
				
				document.objControl.finishGolfList();
			}, 500);
		}
		, getGolfData: function(){
			return this.golfList;
		}
		, setReserveRequest: function(key, val){
			this.reserveRequest[key] = val;
		}
		, getReserveList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.reserveList = [
					{
						"키": "001"
						, "코스키": "001"
						, "코스명": "크리스탈 밸리코스1"
						, "시간": "06:30"
						, "홀명": "18"
						, "가격": "1,090,000"
						, "원가": "1,123,000"
						, "이벤트": "그린피, 카트피, 식사, 선물, 기타"
					}
					, {
						"키": "002"
						, "코스키": "002"
						, "코스명": "크리스탈 밸리코스2"
						, "시간": "06:31"
						, "홀명": "14"
						, "가격": "1,090,001"
						, "원가": "1,123,001"
						, "이벤트": "식사, 기타"
					}
					, {
						"키": "003"
						, "코스키": "003"
						, "코스명": "크리스탈 밸리코스3"
						, "시간": "06:32"
						, "홀명": "13"
						, "가격": "1,090,002"
						, "원가": "1,123,002"
						, "이벤트": "그린피, 카트피, 식사, 기타"
					}
				];
				
				document.objControl.finishReserveList();
			}, 1500);
		}
		, getReserveData: function(){
			return this.reserveList;
		}
		, setReserveInfoRequest: function(key, val){
			this.reserveInfoRequest[key] = val;
		}
		, getReserveInfo: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.reserveInfo = {
					"코스키": "001"
					, "코스명": "SKY72 하늘코스1"
					, "홀명": "15H"
					, "날짜": "2012. 04. 20"
					, "요일": "월요일"
					, "시간": "15:10"
					, "원가": "5,123,000"
					, "가격": "5,090,000"
					, "이벤트": "그린피, 카트피, 기타"
				}
				
				document.objControl.finishReserveInfo();
			}, 1000);
		}
		, getReserveInfoData: function(){
			return this.reserveInfo;
		}
		, setCourseRequest: function(key, val){
			this.courseRequest[key] = val;
		}
		, getCourseInfo: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.courseInfo = {
					"코스키": "001"
					, "코스알림": "내용이 노출됩니다."
					, "코스정보명": "하늘코스111(IN), 하늘코스111(OUT)"
					, "자세히url": "http://192.168.0.82:8080/sky72web/index/index.html"
					, "이미지리스트": [
						"../images/board/del.gif", "../images/board/del.gif", "../images/board/del.gif"
					]
					, "골프장정보": "골프장 정보가 노출됩니다."
					, "주중회원": "230,000 원"
					, "주중비회원": "150,000 원"
					, "주중주중회원": "150,000 원"
					, "주말회원": "230,000 원"
					, "주말비회원": "200,000 원"
					, "주말주중회원": "200,000 원"
					, "기타가격": "150,000 원"
					, "카트비": "80,000원"
					, "캐디비": "일반캐디 10,000원 / 프로캐디 150,000원"
					, "대여채비": "20,000원"
					, "대여화": "10,000원"
					, "코스인원제한": "2인 1팀 / 3인 1팀 / 4인 1팀"
					, "패널티정보": "패널티 정보입니다."
				}
				
				document.objControl.finishCourseInfo();
			}, 1000);
		}
		, getCourseInfoData: function(){
			return this.courseInfo;
		}
		, applyReserveSubmit: function(arg){
			var thisClass = this;
			
//			arg = {
//				"예약키": null
//			}

			//ajax
			setTimeout(function(){
				var ret = {
					"처리결과": "001"
					, "메시지": null
				}
				
				document.objControl.finishApplyReserveSubmit(ret);
			}, 1000);
		}
	}
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objCalendar = null;
		this.objCourseList = null;
		this.objWeekCalendar = null;
		this.objWeekCalendar2 = null;
		this.objCourseTimeList = null;
		this.objAreaList = null;
		this.objGolfList = null;
		this.objReserveList = null;
		this.objReserveInfo = null;
		this.objCourseInfo = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objComm = new clsComm();
			this.objCalendar = new clsCalendar();
			this.objCourseList = new clsCourseList();
			this.objWeekCalendar = new clsWeekCalendar();
			this.objWeekCalendar2 = new clsWeekCalendar2();
			this.objCourseTimeList = new clsCourseTimeList();
			this.objAreaList = new clsAreaList();
			this.objGolfList = new clsGolfList();
			this.objReserveList = new clsReserveList();
			this.objReserveInfo = new clsReserveInfo();
			this.objCourseInfo = new clsCourseInfo();
			
			this._bind();
			
			// 지역정보
			this.objCourseList.spinStart();
			this.objComm.getAreaList();
			
			// 기본날짜 설정
			var tomorow = new Date();
			tomorow.setHours(0);
			tomorow.setMinutes(0);
			tomorow.setSeconds(0);
			tomorow.setMilliseconds(0);
			tomorow.setDate(tomorow.getDate()+1);
			
			var cDate = new Date();
			cDate.setTime(tomorow.getTime());
			
			this.objCalendar.setInfo("달력일", cDate);
			this.objCalendar.setInfo("시작일", tomorow);
			
			this.objWeekCalendar.setDate(tomorow);
			
			// 검색
			$("p.reserv_se img:[alt=검색]").trigger("click");
		}
		, _bind: function(){
			var thisClass = this;
			
			// 달력의 날짜 클릭
			this.objCalendar.$getBtnCalendar().live("click", function(){
				thisClass.setCalendarDate($(this).data("날짜"));
			});
			
			// 좌측 지역선택 체크박스
			this.objCourseList.$getCheckBoxs().live("click", function(){
				thisClass.objCourseList.onCheck($(this));
			});
			
			/// 본문 골프장 선택
			$(this.objGolfList).bind("evtClick", function(){
				thisClass.reserve_list();
			});

			// 달력 이전월
			this.objCalendar.$getBtnPrev().click(function(){
				thisClass.objCalendar.prevMonth();
			});
			
			// 달력 이후월
			this.objCalendar.$getBtnNext().click(function(){
				thisClass.objCalendar.nextMonth();
			});
			
			// 주력 이전
			this.objWeekCalendar.$getBtnPrev().click(function(){
				var newDate = thisClass.objWeekCalendar.getDate();
				newDate.setDate(newDate.getDate()-14);
				
				thisClass.objWeekCalendar.setDate(newDate);
				thisClass.objCalendar.setInfo("시작일", newDate);
			});
			
			// 주력 이후
			this.objWeekCalendar.$getBtnNext().click(function(){
				var newDate = thisClass.objWeekCalendar.getDate();
				newDate.setDate(newDate.getDate()+14);
				
				thisClass.objWeekCalendar.setDate(newDate);
				thisClass.objCalendar.setInfo("시작일", newDate);
			});
			
			// 주력 날짜 선택
			this.objWeekCalendar.$getDateBox().click(function(){
				var idx = thisClass.objWeekCalendar.$getDateBox().index($(this));
				if(idx < 0) idx = thisClass.objWeekCalendar2.$getDateBox().index($(this));
				
				var newDate = new Date();
				newDate.setTime(thisClass.objWeekCalendar.getDate().getTime());
				newDate.setDate(newDate.getDate() + idx);
				
				thisClass.objWeekCalendar.setSelDate(newDate);
				
				thisClass.reserve_list();
			});
			
			// 주력 출력후 2번째 2주력 출력
			$(this.objWeekCalendar).bind("evtFinishDisplay", function(){
				var $obj = arguments[1];
				
				thisClass.objWeekCalendar2.display($obj);
			});
			
			// 검색, 실시간 예약 홈으로
			$("p.reserv_se img:[alt=검색]").add($("img[alt='실시간예약홈으로']").parent("a")).click(function(){
				thisClass.date_reserve();
			});
			
			// my설정
			$("span img[alt='my설정']").click(function(){
				var winMyArea = window.open("../popup/pop_fix.html", "winMyArea", "width=600, height=100, scrollbars=0");
				if(winMyArea) winMyArea.focus();
			});
			
			// 나의 예약내역
			$("div#container section#left_content div.reserv_bt p").click(function(){
				var winMyReserve = window.open("../popup/pop_myreserve.html", "winMyReserve", "width=630, height=320, scrollbars=0");
				if(winMyReserve) winMyReserve.focus();
			});
			
			// 지역선택
			this.objAreaList.$getDisplay().click(function(){
				thisClass.objAreaList.show();
			});
			
			this.objAreaList.$getBtns().live("click", function(){
				thisClass.objAreaList.setKey(thisClass.objAreaList.$getBtns().index($(this)));
				
				// 골프장 리스트 요청
				thisClass.fnGolfListRequest();
			});
			
			// 골프장 선택
			this.objGolfList.$getDisplay().click(function(){
				thisClass.objGolfList.show();
			});
			
			this.objGolfList.$getBtns().live("click", function(){
				thisClass.objGolfList.setKey(thisClass.objGolfList.$getBtns().index($(this)));
				
				// 예약리스트
				thisClass.reserve_list();
			});
			
			// 예약 리스트 정렬 선택
			this.objReserveList.$getBtnOrder().css("cursor", "pointer").click(function(){
				var idx = thisClass.objReserveList.$getBtnOrder().index($(this));
				thisClass.objReserveList.setOrder(idx);
				
				thisClass.reserve_list();
			});
			
			// 예약리스트 상세보기
			this.objReserveList.$getBtnInfos().live("click", function(){
				thisClass.objReserveList.setIdx(thisClass.objReserveList.$getBtnInfos().index($(this)));
				var winAuthCerify = window.open("../popup/pop_certify.html?q_type=info", "winAuthCerify", "width=400, height=340, scrollbars=0");
				if(winAuthCerify) winAuthCerify.focus();
			});
			
			// 예약리스트 예약하기
			this.objReserveList.$getBtnApplys().live("click", function(){
				thisClass.objReserveList.setIdx(thisClass.objReserveList.$getBtnApplys().index($(this)));
				var winAuthCerify = window.open("../popup/pop_certify.html?q_type=apply", "winAuthCerify", "width=400, height=340, scrollbars=0");
				if(winAuthCerify) winAuthCerify.focus();
			});
			
			// 목록버튼
			$("div#container section#main_content").find("img[alt='목록']").parent("a").click(function(){
				thisClass.reserve_list();
			});
			
			// 예약신청버튼
			$("div.btn_area_box02 img[alt='예약신청']").parent("a").click(function(){
				var winAuthCerify = window.open("../popup/pop_certify.html?q_type=apply", "winAuthCerify", "width=400, height=340, scrollbars=0");
				if(winAuthCerify) winAuthCerify.focus();
			});
			
			// sms 알림버튼
			$("img[alt='sms알림']").parent("a").click(function(){
				var winSms = window.open("../popup/pop_sms.html", "winSms", "width=400, height=300, scrollbars=0");
				if(winSms) winSms.focus();
			});
			
			// e-mail 알림버튼
			$("img[alt='e-mail알림']").parent("a").click(function(){
				var winEmail = window.open("../popup/pop_email.html", "winEmail", "width=700, height=300, scrollbars=0");
				if(winEmail) winEmail.focus();
			});
		}
		// my설정 완료
		, finishMySetting: function(w){
			if(w) w.close();
			document.location.reload();
		}
		// 날짜별 코스리스트
		, date_reserve: function(){
			this.objWeekCalendar.enable();
			this.objCourseTimeList.enable();
			
			this.objAreaList.disable();
			this.objGolfList.disable();
			this.objWeekCalendar2.disable();
			this.objReserveList.disable();
			
			this.objReserveInfo.disable();
			this.objCourseInfo.disable();
			$("div.btn_area_box02").hide();
			$("p").has("img[alt=목록]").hide();
			$("div#idReserveOk").hide();
			
			var szCourse = this.objCourseList.getValue();
			var sDate = this.objCalendar.getSDate();
			
			this.objCourseTimeList.setSatIndexs(this.objWeekCalendar.getSatIndexs());
			this.objCourseTimeList.setSunIndexs(this.objWeekCalendar.getSunIndexs());
			
			this.objComm.setCourseTimeRequest("코스키", szCourse);
			this.objComm.setCourseTimeRequest("시작일", sDate.getFullYear() + "-" + (sDate.getMonth()+1) + "-" + sDate.getDate());
			
			this.objCourseTimeList.spinStart();
			this.objComm.getCourseTimeList();
		}
		// 특정일 예약리스트
		, reserve_list: function(){
			this.objWeekCalendar.disable();
			this.objCourseTimeList.disable();
			
			this.objAreaList.enable();
			this.objGolfList.enable();
			this.objWeekCalendar2.enable();
			this.objReserveList.enable();
			
			this.objReserveInfo.disable();
			this.objCourseInfo.disable();
			$("div.btn_area_box02").hide();
			$("p").has("img[alt=목록]").hide();
			$("div#idReserveOk").hide();
			
			var selDate = this.objWeekCalendar.getSelDate();
			
			this.objComm.setReserveRequest("지역키", this.objAreaList.getValue());
			this.objComm.setReserveRequest("골프장키", this.objGolfList.getValue());
			this.objComm.setReserveRequest("날짜", selDate.getFullYear() + "-" + (selDate.getMonth()+1) + "-" + selDate.getDate());
			this.objComm.setReserveRequest("갯수", 10);
			this.objComm.setReserveRequest("정렬", this.objReserveList.getOrder());
			
			this.objReserveList.spinStart();
			this.objComm.getReserveList();
		}
		// 특정예약정보
		, reserve_info: function(){
			var reserveKey = this.objReserveList.getKey();
			var courseKey = this.objReserveList.getCourseKey();
			
			if(!(courseKey && reserveKey)) return;
			
			this.objWeekCalendar.disable();
			this.objCourseTimeList.disable();
			
			this.objAreaList.enable();
			this.objGolfList.enable();
			this.objWeekCalendar2.enable();
			this.objReserveList.disable();
			
			this.objReserveInfo.enable();
			this.objCourseInfo.enable();
			$("div.btn_area_box02").show();
			$("p").has("img[alt=목록]").show();
			$("div#idReserveOk").hide();
			
			this.objReserveInfo.spinStart();
			this.objComm.setReserveInfoRequest("예약키", reserveKey);
			this.objComm.getReserveInfo();
			
			this.objCourseInfo.spinStart();
			this.objComm.setCourseRequest("코스키", courseKey);
			this.objComm.getCourseInfo();
		}
		// 예약완료
		, reserve_ok: function(){
			var reserveKey = this.objReserveList.getKey();
			
			if(!reserveKey) return;
			
			this.objWeekCalendar.disable();
			this.objCourseTimeList.disable();
			
			this.objAreaList.disable();
			this.objGolfList.disable();
			this.objWeekCalendar2.disable();
			this.objReserveList.disable();
			
			this.objReserveInfo.enable();
			this.objCourseInfo.disable();
			$("div.btn_area_box02").hide();
			$("p").has("img[alt=목록]").hide();
			$("div#idReserveOk").show();
		}
		// 지역정보 완료
		, finishAreaList: function(){
			var thisData = this.objComm.getAreaData();
			
			this.objComm.getCourseList();
			// 좌측 지역선택 출력
			this.objCourseList.setAreaList(document.objUtil.objectCopy(thisData));
			
			// 리스트 출력
			this.objCourseTimeList.setList(document.objUtil.objectCopy(thisData));
			
			// 본문 지역선택
			this.objAreaList.setList(document.objUtil.objectCopy(thisData));
		}
		// 코스정보 완료
		, finishCourseList: function(){
			var thisData = this.objComm.getCourseData();
				
			this.objCourseList.spinEnd();
			this.objCourseList.display();
			this.objCourseList.setCourseList(thisData);
		}
		// 코스리스트 완료
		, finishCourseTimeList: function(){
			var thisData = this.objComm.getCourseTimeData();
			
			this.objCourseTimeList.spinEnd();
			
			this.objCourseTimeList.setCourseList(thisData);
		}
		// 골프장 리스트 완료
		, finishGolfList: function(){
			var thisData = this.objComm.getGolfData();
				
			this.objGolfList.setList(thisData);
		}
		// 예약리스트 완료
		, finishReserveList: function(){
			var thisData = this.objComm.getReserveData();
				
			this.objReserveList.spinEnd();
			this.objReserveList.setList(thisData);
		}
		// 예약정보 완료
		, finishReserveInfo: function(){
			var thisData = this.objComm.getReserveInfoData();
				
			this.objReserveInfo.spinEnd();
			this.objReserveInfo.setInfo(thisData);
		}
		// 코스정보 완료
		, finishCourseInfo: function(){
			var thisData = this.objComm.getCourseInfoData();
				
			this.objCourseInfo.spinEnd();
			this.objCourseInfo.setInfo(thisData);
		}
		// 예약완료
		, finishApplyReserveSubmit: function(){
			var ret = arguments[1];
			
			document.objGlobal.spinEnd();
			this.reserve_ok();
		}
		// 인증완료 후
		, certified: function(w, actionType, reserveKey){
			w.close();
			
			this.objReserveList.setKey(reserveKey);
			switch(actionType){
				case "info":
					this.reserve_info();
					break;
				case "apply":
					var winApplyReserve = window.open("../popup/pop_offer.html", "winApplyReserve", "width=400, height=300, scrollbars=0");
					if(winApplyReserve) winApplyReserve.focus();
					break;
			}
		}
		// 예약키 전달
		, getReserveKey: function(){
			return this.objReserveList.getKey();
		}
		// 예약하기
		, applyReserve: function(w, reserveKey){
			w.close();
			
			// 예약
			document.objGlobal.spinStart("sending...");
			this.objReserveList.setKey(reserveKey);
			this.objComm.applyReserveSubmit({
				"예약키": reserveKey
			});
		}
		// 달력선택
		, setCalendarDate: function(objDate){
			if(objDate) this.objCalendar.setInfo("시작일", objDate);
			var newDate = this.objCalendar.getSDate();
				
			//주력에 전달
			this.objWeekCalendar.setDate(newDate);
			
			// 검색
			this.date_reserve();
		}
		// 골프장 리스트 요청
		, fnGolfListRequest: function(){
			this.objGolfList.reset();
			var areaKey = this.objAreaList.getValue();
			
			if(!areaKey) return;
			
			// 골프장 리스트 요청
			this.objComm.setGolfRequest("지역키", areaKey);
			this.objComm.getGolfList();
			
			this.reserve_list();
		}
	}
	
	document.objControl = new clsControl();
});
